<template>
  <div>
    <PageHeader title="新增/编辑文章" />
    <div class="form-container">
      <el-form :model="formData" label-width="100px" ref="formRef" :rules="rules">
        <el-form-item label="文章标题" prop="title">
          <el-input v-model="formData.title" style="width: 300px" placeholder="请输入文章标题" />
        </el-form-item>
        <el-form-item label="文章内容" prop="content">
          <EditorWang v-model="formData.content" />
        </el-form-item>
      </el-form>

      <div class="flex_aic_jcc">
        <el-button @click="handleBack">返回</el-button>
        <el-button type="primary" @click="submitForm">保存并返回</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import PageHeader from "@/components/pageHeader.vue";
import { ref } from "vue";
import EditorWang from "@/components/editorWang.vue";
import { useRouter } from "vue-router";
const router = useRouter();
const formData = ref({
  title: "",
  content: "",
});
const rules = ref({
  title: [{ required: true, message: "请输入文章标题" }],
  content: [{ required: true, message: "请输入文章内容" }],
});
const formRef = ref(null);
const submitForm = () => {
  console.log(formData.value);
  formRef.value.validate((valid) => {
    if (valid) {
      console.log(formData.value);
    }
  });
};
const handleBack = () => {
  router.back();
};
</script>

<style scoped></style>
